

import React from 'react';
import { View, Text, TouchableOpacity } from 'react-native';
import { FontAwesome6 } from '@expo/vector-icons';
import styles from './styles';

interface CCData {
  id: string;
  title: string;
  applicant: string;
  initiateTime: string;
  status: 'approved' | 'pending' | 'rejected' | 'processing';
  ccTime: string;
  department: string;
  approver?: string;
  currentNode?: string;
  rejectReason?: string;
}

interface CCItemProps {
  data: CCData;
  onPress: () => void;
}

const CCItem: React.FC<CCItemProps> = ({ data, onPress }) => {
  const getStatusStyle = (status: string) => {
    switch (status) {
      case 'approved':
        return styles.statusApproved;
      case 'pending':
        return styles.statusPending;
      case 'rejected':
        return styles.statusRejected;
      case 'processing':
        return styles.statusProcessing;
      default:
        return styles.statusPending;
    }
  };

  const getStatusText = (status: string) => {
    switch (status) {
      case 'approved':
        return '已通过';
      case 'pending':
        return '待审批';
      case 'rejected':
        return '已驳回';
      case 'processing':
        return '审批中';
      default:
        return '待审批';
    }
  };

  const getBottomRightText = () => {
    if (data.status === 'approved' && data.approver) {
      return `最终审批人：${data.approver}`;
    }
    if (data.status === 'processing' && data.currentNode) {
      return `当前节点：${data.currentNode}`;
    }
    if (data.status === 'rejected' && data.rejectReason) {
      return `驳回原因：${data.rejectReason}`;
    }
    if (data.status === 'pending' && data.currentNode) {
      return `当前节点：${data.currentNode}`;
    }
    return '';
  };

  return (
    <TouchableOpacity style={styles.container} onPress={onPress}>
      <View style={styles.content}>
        <View style={styles.mainInfo}>
          <Text style={styles.title}>{data.title}</Text>
          <Text style={styles.applicantInfo}>
            申请人：{data.applicant} | 发起时间：{data.initiateTime}
          </Text>
          <View style={styles.statusRow}>
            <View style={[styles.statusBadge, getStatusStyle(data.status)]}>
              <Text style={styles.statusText}>{getStatusText(data.status)}</Text>
            </View>
            <Text style={styles.ccTime}>抄送时间：{data.ccTime}</Text>
          </View>
        </View>
        <FontAwesome6 name="chevron-right" size={14} color="#6B7280" style={styles.chevronIcon} />
      </View>
      <View style={styles.bottomInfo}>
        <Text style={styles.department}>{data.department}</Text>
        <Text style={styles.bottomRightText}>{getBottomRightText()}</Text>
      </View>
    </TouchableOpacity>
  );
};

export default CCItem;

